<% layout('/layouts/default.html', {title: '任务部署信息表(主)管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-tools pull-left" style="position: relative">
				<ul class="nav nav-tabs bangPing-tabs">
					<li ><a href="${ctx}/taskdeploy/dcSupTaskInfoRefine/list">${text('待提交')}</a></li>
					<li class="active"><a href="${ctx}/taskdeploy/dcSupTaskInfoRefine/listed">${text('已提交')}</a></li>
				</ul>
			</div>
			<#form:form id="searchForm" model="${dcSupTaskInfo}" action="${ctx}/taskdeploy/dcSupTaskInfoRefine/queryListData?normalFlag=3" method="post" class="form-inline"
			data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
			<div style="float: right">



				<div class="form-group">
					<label class="control-label">${text('任务年度')}：</label>
					<div class="control-inline width-120">
						<#form:select path="taskYear" items="${yearList}" blankOption="true" data-placeholder="请选择" itemLabel="yearLabel" itemValue="yearValue" class="form-control width-120" defaultValue="${currentYear}"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('任务标题')}：</label>
					<div class="control-inline width-160">
						<#form:input path="taskTitle" maxlength="200" class="form-control width-160" placeholder="请输入任务标题"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('任务类型')}：</label>
					<div class="control-inline width-160">
						<#form:select path="taskTypeCode" items="${dicts}" blankOption="true" data-placeholder="请选择" itemLabel="dictLabel" itemValue="dictValue" class="form-control width-160"/>
					</div>
				</div>
				<!--<div class="form-group">
					<label class="control-label">${text('任务状态')}：</label>
					<div class="control-inline width-160">
						<#form:select path="taskStatus" dictType="dc_task_status"  class="form-control width-220" data-placeholder="请选择" blankOption="true"/>
					</div>
				</div>-->
				<div class="form-group">
					<!--					<label class="control-label">${text('数据过滤')}：</label>-->
					<div class="control-inline width-90">
						<% if(hasRole('other_office')){ %>
						<% var items = [{label:'我的',value:'0'}]; %>
						<#form:select path="dataLimit" items="${items}" itemLabel="label" itemValue="value" defaultValue="0" class="form-control required" />
						<% } else{ %>
						<% var items = [{label:'我的',value:'0'},{label:'本单位',value:'1'}]; %>
						<#form:select path="dataLimit" items="${items}" itemLabel="label" itemValue="value" defaultValue="0" class="form-control required" />
						<% } %>

					</div>
				</div>
				<div class="form-group" >
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button onclick="cz();" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</div>
		</#form:form>
		</div>
		<div class="box-body">
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
	//重置
	$(function () {
		if('${dcSupTaskInfo.remarks3}'){
			$("#dataGrid").jqGrid('GridUnload');
			$("#pageNo").val('${dcSupTaskInfo.remarks3}');
			$("#pageSize").val('${dcSupTaskInfo.remarks4}');
			$('#dataGrid').dataGrid({
				searchForm: $("#searchForm"),
				sortableColumn: false, // 列表不允许排序
				columnModel: [
					{header:'${text("主键")}', name:'id', index:'a.id', width:150, align:"left", hidden:true},
					{header:'${text("督办字号")}', name:'messageNumber', index:'a.message_number', width:100, align:"left", formatter: function(val, obj, row, act){
							if (val) {
								return val;
							} else {
								return "暂无字号";
							}
						}},
					{header:'${text("任务标题")}', name:'taskTitle', index:'a.task_title', width:150, align:"left", formatter: function(val, obj, row, act){
							var pageNo = $("#pageNo").val();
							var pageSize = $("#pageSize").val();
							return '<a href="${ctx}/action/dcSupTaskAction/listOrg?normalFlag=3&taskId='+row.id+'&remarks3='+pageNo+'&remarks4='+pageSize+'" class="btnList" data-title="${text("牵头责任单位详情")}">'+(val||'暂无标题')+'</a>';
						}},
					{header:'${text("任务类型")}', name:'taskTypeName', index:'a.task_type_name', width:150, align:"left"},
					{header:'${text("任务内容")}', name:'taskContent', index:'a.task_content', width:150, align:"left", formatter: function(val, obj, row, act){
							return '<a href="${ctx}/taskdeploy/dcSupTaskInfo/detailForm?id='+row.id+'" class="btnList" data-title="${text("督办任务信息")}">'+(val||'暂无内容')+'</a>';
						}},
					{header:'${text("分解进度")}', name:'refineProgress', width:150, align:"center"},
					{header:'${text("牵头领导")}', name:'taskLeaderName', index:'a.task_leader_name', width:150, align:"left"},
					/*	{header:'${text("调度人")}', name:'contactName', index:'a.contact_name', width:100, align:"left"},*/
					{header:'${text("牵头责任单位")}', name:'taskLeaderOrgName', index:'a.task_leader_org_name', width:150, align:"left",formatter:function (val,obj,row,act) {
							return '<a   href="#" onclick=showTaskLeaderOrg("' + row.id + '")   >'+val+'</a>'
						}},
					{header:'${text("任务状态")}', name:'taskStatus', index:'a.task_status', width:150, align:"center"
						,formatter: function(val, obj, row, act){
							return js.getDictLabel(${@DictUtils.getDictListJson('dc_task_status')}, val, '${text("未知")}', true);
						}},
					{header:'${text("操作")}', name:'actions', width:260,align:"center", formatter: function(val, obj, row, act){
							var actions = [];
							if(1==1) {
							/*	actions.push('<a style="cursor:pointer;"  onclick=arrangeTask("' + row.id + '")  title="${text("整理任务")}" ><span class="btn btn-primary btn-xs">整理任务</span></a>&emsp;');
								actions.push('<a href="#" style="cursor:pointer;" onclick=arrangeHis("' + row.id + '")  class="btn btn-primary btn-xs" title="${text("整理历史")}">整理历史</a>&nbsp;&emsp;');*/				}
							return actions.join('');
						}}
				],
				page: '${dcSupTaskInfo.remarks3}',	// 当前页码
				rowNum: '${dcSupTaskInfo.remarks4}',
				// 加载成功后执行事件
				ajaxSuccess: function(data){

				}
			});
		}
	})
	function cz(){
		searchForm.reset();
		$('#dataGrid').dataGrid('reloadGrid');
	}

	// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	sortableColumn: false, // 列表不允许排序
	columnModel: [
		{header:'${text("主键")}', name:'id', index:'a.id', width:150, align:"left", hidden:true},
		{header:'${text("督办字号")}', name:'messageNumber', index:'a.message_number', width:100, align:"left", formatter: function(val, obj, row, act){
				if (val) {
					return val;
				} else {
					return "暂无字号";
				}
			}},
		{header:'${text("任务标题")}', name:'taskTitle', index:'a.task_title', width:150, align:"left", formatter: function(val, obj, row, act){
				var pageNo = $("#pageNo").val();
				var pageSize = $("#pageSize").val();
				return '<a href="${ctx}/action/dcSupTaskAction/listOrg?remarks1=1&normalFlag=3&taskId='+row.id+'&remarks3='+pageNo+'&remarks4='+pageSize+'" class="btnList" data-title="${text("牵头责任单位详情")}">'+(val||'暂无标题')+'</a>';
			}},
		{header:'${text("任务类型")}', name:'taskTypeName', index:'a.task_type_name', width:150, align:"left"},
		{header:'${text("任务内容")}', name:'taskContent', index:'a.task_content', width:150, align:"left", formatter: function(val, obj, row, act){
				return '<a href="${ctx}/taskdeploy/dcSupTaskInfo/detailForm?id='+row.id+'" class="btnList" data-title="${text("督办任务信息")}">'+(val||'暂无内容')+'</a>';
			}},
		{header:'${text("分解进度")}', name:'refineProgress', width:150, align:"center"},
		{header:'${text("牵头领导")}', name:'taskLeaderName', index:'a.task_leader_name', width:150, align:"left"},
	/*	{header:'${text("调度人")}', name:'contactName', index:'a.contact_name', width:100, align:"left"},*/
		{header:'${text("牵头责任单位")}', name:'taskLeaderOrgName', index:'a.task_leader_org_name', width:150, align:"left"
			,formatter:function (val,obj,row,act) {
				return '<a   href="#" onclick=showTaskLeaderOrg("' + row.id + '")   >'+val+'</a>'
			}},
		{header:'${text("任务状态")}', name:'taskStatus', index:'a.task_status', width:150, align:"center"
			,formatter: function(val, obj, row, act){
				return js.getDictLabel(${@DictUtils.getDictListJson('dc_task_status')}, val, '${text("未知")}', true);
			}},
		{header:'${text("操作")}', name:'actions', width:260,align:"center", formatter: function(val, obj, row, act){
				var actions = [];
				if(1==1) {
					/*actions.push('<a style="cursor:pointer;"  onclick=selectTaskLeader("' + row.id + '","'+row.taskLeader+'")  title="${text("选择领导")}" ><span class="btn btn-primary btn-xs">选择领导</span></a>&emsp;');
					actions.push('<a style="cursor:pointer;"  onclick=arrangeTask("' + row.id + '")  title="${text("整理任务")}" ><span class="btn btn-primary btn-xs">整理任务</span></a>&emsp;');
					actions.push('<a href="#" style="cursor:pointer;" onclick=arrangeHis("' + row.id + '")  class="btn btn-primary btn-xs" title="${text("整理历史")}">整理历史</a>&nbsp;&emsp;');	*/			}
				return actions.join('');
			}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});

	function showSubTask(id) {
		js.addTabPage(null, "子任务明细","${ctx}/action/dcSupTaskAction/listOrg?taskId="+id , true);
	}

	function editTask(id) {
		js.addTabPage(null, "编辑督办任务","${ctx}/taskdeploy/dcSupTaskInfoRefine/form?id="+id , true);
	}

	function arrangeTask(taskId){
		js.addTabPage(null, "整理内容","${ctx}/taskdeploy/dcSupTaskInfo/arrangeTask?taskId="+taskId , true);
	}

	function arrangeHis(id) {
		js.layer.open({
			type: 2,
			title: ['整理历史'],
			area: ['1000px', '860px'],
			scrollbar: true,
			shadeClose: false,
			content: "${ctx}/arrange/dcSupTaskInfoArrange?taskId="+id,
			btn1: function (index, layero) {
			},
			end:function () {
				$('#dataGrid').dataGrid('refresh', 1, 20);
			}
		});
	}

	function selectTaskLeader(id,taskLeader){
		var userList = '${toJson(userList)}';
		var list =  JSON.parse(userList);
		var radioHtml='';
		$.each(list,function(index,item){
			if(taskLeader.match(item.userCode)){
				radioHtml= radioHtml+'<div class="dbd"><input type="checkbox" checked="checked" name="userCode" value="'+item.userCode+'"/><span class="xbd">'+item.userName+'</span></div> '
			}else {
				radioHtml= radioHtml+'<div class="dbd"><input type="checkbox" name="userCode" value="'+item.userCode+'"/><span class="xbd">'+item.userName+'</span></div> '
			}
		})
		layer.open({
			type: 1
			,title: ['牵头领导人', 'font-size:18px; color:orange;'] //不显示标题栏
			,btn: ['确认', '取消']
			,btnAlign: 'c'
			,area: ['400px','600px']
			,moveType: 1 //拖拽模式，0或者1
			,content: radioHtml

			,yes: function(layero){
				var userCode = "";
				var userName="";
				$("input:checkbox[name='userCode']:checked").each(function(i) {
					userCode += $(this).val();
					if($("input:checkbox[name='userCode']:checked").length-1!=i){
						userCode+=",";
					}
				});
				$("input:checkbox[name='userCode']:checked").each(function(i) {
					userName += $(this).next("span").text();
					if($("input:checkbox[name='userCode']:checked").length-1!=i){
						userName +=",";
					}
				});
				$.ajax({
					url: "${ctx}/taskdeploy/dcSupTaskInfo/updateTaskLeader",
					type: "post",
					cache: false,
					async:false,
					data: {
						"taskLeader":userCode,
						"taskLeaderName":userName,
						"id":id
					},
					success: function(data){
						$('#dataGrid').dataGrid('refresh', 1, 20);

					}
				});


			}
		});
	}

	function showTaskLeaderOrg(taskNo) {
		js.layer.open({
			type: 2,
			title: '牵头责任单位',
			area: ['700px', '500px'],
			content: "${ctx}/taskdeploy/dcSupTaskInfo/showTaskLeaderOrg?taskNo=" + taskNo,
			btn: [],
			btn1: function (index, layero) {

			}
		});
	}

</script>
<style>
	.dbd{
		padding: 10px;
		border-bottom: 1px solid gray;
		border-right: 1px solid gray;
		border-left: 1px solid gray;
		margin: auto 10px;
	}
	.dbd:nth-child(1){
		padding: 10px;
		border-bottom: 1px solid gray;
		border-top: 1px solid gray;
	}
	.xbd{
		margin-left: 10px;
	}
</style>